var user;
var listData;
apiready = function() {
	$api.getUserInf(function(userInf) {
		$('#owinfName').text('业主名字：' + userInf.nickName);
		$('#owinfMobile').text('手机号：' + userInf.mobile);
		user = userInf
		obtainData();

	});
};

function obtainData(type) {
	api.showProgress();
	var reqData = {
		account: user.account,
		status: type
	}
	if (type == "0") {
		delete reqData.status;
	}
	$api.do_post('/api/ropertyRepair/list', {
		body: JSON.stringify(reqData)
	}, function(datas) {
		listData = datas;
		if (datas) {
			var html = '';
			if (datas.length < 1) {
				html += '<div class="payment_box"><div class="payment_data clearfix"><span>暂无报修信息...</span></div></div>';
			}
			for (var i = 0; i < datas.length; i++) {
				if (['待接单', '已派单', '已评价', '维修中'].indexOf(datas[i].status) > -1) {
					var t = datas[i].serviceType ? datas[i].amount : '待确认';
					html += '<li><div class="re_order_title">维修项目：' + datas[i].postType + '</div><p><span>维修内容：</span>' + datas[i].repairContent + '</p><p><span>完成情况：</span>' + datas[i].status + '</p><p><span>维修金额：</span>' + t + '</p></li>';
				}
				if ('待确认' == datas[i].status) {
					html += '<li><div class="reForm_title">维修项目：' + datas[i].postType + '<input type="button" value="维修确认" class="btn_flat_small"  onclick="verifyRepairComfirm(\'' + datas[i]._id + '\')" /></div><p><span>维修内容：</span>' + datas[i].repairContent + '</p><p><span>完成情况：</span>' + datas[i].status + '</p><p><span>维修金额：</span>' + datas[i].amount + '</p></li>';
				}
				if ('待验收' == datas[i].status) {
					html += '<li><div class="reForm_title">维修项目：' + datas[i].postType + '<input type="button" value="验收确认" class="btn_flat_small"  onclick="verifyRepair(\'' + datas[i]._id + '\')" /></div><p><span>维修内容：</span>' + datas[i].repairContent + '</p><p><span>完成情况：</span>' + datas[i].status + '</p><p><span>维修金额：</span>' + datas[i].amount + '</p></li>';
				}
				if ('维修完成' == datas[i].status) {
					html += '<li><div class="reForm_title">维修项目：' + datas[i].postType + '<input type="button" value="去评价" class="btn_flat_small" onclick="toEvaluate(\'' + datas[i]._id + '\')" /></div><p><span>维修内容：</span>' + datas[i].repairContent + '</p><p><span>完成情况：</span>' + datas[i].status + '</p><p><span>维修金额：</span>' + datas[i].amount + '</p></li>';
				}
			}
			$('#reOrderList').html(html);
		} else {
			$('#reOrderList').html("暂无报修记录");
		}
	});
}

function verifyRepair(repairId) {


	$api.do_post("/api/ropertyRepair/confirm", {
		body: JSON.stringify({
			repairId: repairId
		})
	}, function(ret) {
		if (ret.code == '0') {
			$api.toastMsg("确认成功");
			location.reload();
		}
	})

}

function verifyRepairComfirm(repairId) {
	  api.openWin({
            name: 'winName',
            url:  'repairOrder_comfirm.html',
            bounces: false,
         	pageParam:{'repairId':repairId}
        });
	//$api.mOpenWin('repairComfirm', 'repairOrder_comfirm.html',repairId:repairId"}");
}

function toEvaluate(repairId) {

	$api.mOpenWin('repairEvaluate', 'repairEvaluate.html', {
		repairId: repairId
	});
}

$('#Select2').on('change', function() {
	var status = $('#Select2').val();
	obtainData(status);
})